module('basic');

test('ADT.ADT', function() {
  expect(2);

  var adt = new ADT();

  equals(
    adt.getTimestamp(),
    0,
    'adt.getTimestamp()');

  equals(
    adt.getTZOffset(),
    0,
    'adt.getTZOffset()');
});

test('ADT.fromTimestamp', function() {
  expect(4);

  var positive = ADT.fromTimestamp(1287782850);
  var negative = ADT.fromTimestamp(-1287782850);

  equals(
    positive.getTimestamp(),
    1287782850,
    'positive.getTimestamp()');

  equals(
    positive.getTZOffset(),
    ADT.getLocalTZOffset(),
    'positive.getTZOffset()');

  equals(
    negative.getTimestamp(),
    -1287782850,
    'negative.getTimestamp()');

  equals(
    negative.getTZOffset(),
    ADT.getLocalTZOffset(),
    'negative.getTZOffset()');
});

test('ADT.fromJSDate', function() {
  expect(4);

  var positive = ADT.fromJSDate(new Date(2010, 10 - 1, 22, 18, 59, 43));
  var negative = ADT.fromJSDate(new Date(1910, 10 - 1, 22, 18, 59, 43));

  equals(
    positive.getTimestamp(),
    1287773983 - ADT.getLocalTZOffset(),
    'positive.getTimestamp()');

  equals(
    positive.getTZOffset(),
    ADT.getLocalTZOffset(),
    'positive.getTZOffset()');

  equals(
    negative.getTimestamp(),
    -1867986017 - ADT.getLocalTZOffset(),
    'negative.getTimestamp()');

  equals(
    negative.getTZOffset(),
    ADT.getLocalTZOffset(),
    'negative.getTZOffset()');
});

test('ADT.now', function() {
  expect(3);

  var before = ((new Date()).getTime() / 1000) | 0;
  var now = ADT.now();
  var after = ((new Date()).getTime() / 1000) | 0;

  equals(
    now.getTimestamp() >= before,
    true,
    'now.getTimestamp() >= before'
  );

  equals(
    now.getTimestamp() <= after,
    true,
    'now.getTimestamp() <= after'
  );

  equals(
    now.getTZOffset(),
    ADT.getLocalTZOffset(),
    'now.getTZOffset()');
});

test('ADT.prototype.setTimestamp', function() {
  expect(4);

  var positive = new ADT();
  positive.setTimestamp(1287782850);

  var negative = new ADT();
  negative.setTimestamp(-1287782850);

  equals(
    positive.getTimestamp(),
    1287782850,
    'positive.getTimestamp()');

  equals(
    positive.getTZOffset(),
    0,
    'positive.getTZOffset()');

  equals(
    negative.getTimestamp(),
    -1287782850,
    'negative.getTimestamp()');

  equals(
    negative.getTZOffset(),
    0,
    'negative.getTZOffset()');
});

test('ADT.prototype.setTZOffset', function() {
  expect(4);

  var positive = new ADT();
  positive.setTZOffset(3600);

  var negative = new ADT();
  negative.setTZOffset(-3600);

  equals(
    positive.getTimestamp(),
    0,
    'positive.getTimestamp()');

  equals(
    positive.getTZOffset(),
    3600,
    'positive.getTZOffset()');

  equals(
    negative.getTimestamp(),
    0,
    'negative.getTimestamp()');

  equals(
    negative.getTZOffset(),
    -3600,
    'negative.getTZOffset()');
});

test('ADT.prototype.cacheFill', function() {
  expect(1);

  var valid_by_cache_fill = new ADT();
  valid_by_cache_fill.cacheFill();

  equals(
    valid_by_cache_fill.isCacheFilled(),
    true,
    'valid_by_cache_fill.isCacheFilled()');
});

test('ADT.prototype.cacheInvalidate', function() {
  expect(4);

  var invalid_by_construct = new ADT();

  var invalid_by_cache_invalidate = new ADT();
  invalid_by_cache_invalidate.cacheFill();
  invalid_by_cache_invalidate.cacheInvalidate();

  var invalid_by_set_timestamp = new ADT();
  invalid_by_set_timestamp.cacheFill();
  invalid_by_set_timestamp.setTimestamp(0);

  var invalid_by_set_tz_offset = new ADT();
  invalid_by_set_tz_offset.cacheFill();
  invalid_by_set_tz_offset.setTZOffset(0);

  equals(
    invalid_by_construct.isCacheFilled(),
    false,
    'invalid_by_construct.isCacheFilled()');

  equals(
    invalid_by_cache_invalidate.isCacheFilled(),
    false,
    'invalid_by_cache_invalidate.isCacheFilled()');

  equals(
    invalid_by_set_timestamp.isCacheFilled(),
    false,
    'invalid_by_set_timestamp.isCacheFilled()');

  equals(
    invalid_by_set_tz_offset.isCacheFilled(),
    false,
    'invalid_by_set_tz_offset.isCacheFilled()');
});
